enyo.kind({
	name: "AssessmentUI_ReportDetail",
	kind: "AssessmentUI_PanelBase",
	
	caption: "Assessment Report",
	submitLeftCaption: "Back Home",
	classes: "panel-body",
	
	components: [
		{kind: "onyx.Groupbox", classes: "groupbox", components: [
			{kind: "onyx.GroupboxHeader", name: "typeHeader", classes: "group-header", content: "Header"},
			{name: "typeContent", content: "Content", classes: "content", allowHtml: true, style: "font-size: 14px;"}
		]},
		{kind: "onyx.Groupbox", classes: "groupbox", components: [
			{kind: "onyx.GroupboxHeader", name: "descriptionHeader", classes: "group-header", content: "Header"},
			{name: "descriptionContent", content: "Content", classes: "content", allowHtml: true, style: "font-size: 14px;"}
		]},
		{kind : "hpit.Divider", name: "overviewDivider", caption : "Overview", showing: false},
		{name: "overviewContent", allowHtml: true},
		{kind : "hpit.Divider", name: "summaryDivider", caption : "Package Summary", showing: false},
		{name: "summaryContent", allowHtml: true}
	],
	
	back: function() {
		this.parentWnd.switchView("report_run");
	},
	
	submitLeft: function() {
		this.parentWnd.switchView("home");
	},
	
	submitRight: function() {
		this.showMsg("Test to show a popup with some text");
	},
	
	create: function() {
		this.inherited(arguments);
		this.initPanel();
	},
	
	initPanel: function() {
		this.showScrim();
		
		//call the service
		var service = new hpit.WebService();
		service.setUrl(AssessmentUI_Config.getServiceUrl_GetReport());
		service.setHeaders(AssessmentUI_Config.getCommonServiceHeader());
		service.setParams({value0: 12345});
		service.call(this, "processResponse");
	},
	
	processResponse: function(inSender, inResponse) {
		if(inResponse.statusCode === 200) {
			this.showReport(inResponse);
			this.hideScrim();
		}
		else {
			this.showMsg("Error response of service (StatusCode: " + inResponse.statusCode + ")");
		}
	},
	
	percentageMeterSplit : function(value, percentage1, percentage2, percentage3, color1, color2, color3) {
		var html = "";
		if (percentage1 < 0) percentage1 = 0;
		if (percentage2 < 0) percentage2 = 0;
		if (percentage3 < 0) percentage3 = 0;
		var total = percentage1+percentage2+percentage3;
		if (total > 100) {
			percentage1 = percentage1 * 100 / total;
			percentage2 = percentage2 * 100 / total;
			percentage3 = percentage3 * 100 / total;
			total = 100;
		}
		var percentage4 = 100 - total;
		html += "<table><tr><td>";
		html += "<table style=\"width: 200px; height: 14px; float: left;\"cellspacing=\"0\" cellpadding=\"0\">";
		html += "<tr>";
		if (percentage1>0){
			html += "<td width=\"" + percentage1 + "%\" style=\"background-color: " + color1 + "\"></td>";
		}
		if (percentage2>0){
			html += "<td width=\"" + percentage2 + "%\" style=\"background-color: " + color2 + "\"></td>";
		}
		if (percentage3>0){
			html += "<td width=\"" + percentage3 + "%\" style=\"background-color: " + color3 + "\"></td>";
		}
		if (percentage4>0){
			html += "<td width=\"" + percentage4 + "%\" style=\"background-color: #e7e7e7\"></td>";
		}
		html += "</tr>";
		html += "</table>";
		html += "</td><td style=\"font-size: 14px;\">";
		html += value;
		html += "</td></tr></table>";
		return html;
	},
	
	appendPackageSummaryTR : function(styleName, pkg, exitStatus, startTime, endTime) {
		var strStartTime = startTime == null ? " " : startTime;
		var strEndTime = endTime == null ? " " : endTime;
		return "<tr><td style=\""+ styleName + "\">" + pkg + "</td><td style=\""+ styleName + " width: 400px;\">" + exitStatus + "</td><td style=\""+ styleName + "\">" + strStartTime + "</td><td style=\""+ styleName + "\">" + strEndTime + "</td></tr>";
	},
	
	showReport: function(inResponse) {
		this.$.overviewDivider.setShowing(true);
		this.$.summaryDivider.setShowing(true);
		
		this.$.typeHeader.setContent("HP System Health Check Assessment - Detailed Report");
		
		var typeContentHtml = "";
		typeContentHtml += "Created: " + inResponse.payload.createdTime + "<br />";
		typeContentHtml += "Analysis Start Time: " + inResponse.payload.analysisStartTime + "<br />";
		typeContentHtml += "Collection Time: " + inResponse.payload.collectionTime + "<br />";
		typeContentHtml += inResponse.payload.customerName + ", " + inResponse.payload.address + ", " + inResponse.payload.city + ", " + inResponse.payload.state + ", " + inResponse.payload.countryCode + "(" + inResponse.payload.postalCode + ")";
		this.$.typeContent.setContent(typeContentHtml);
		
		this.$.descriptionHeader.setContent("About System Health Check Assessments");
		this.$.descriptionContent.setContent(inResponse.payload.systemHealthCheckAssessmentsDescription);

		var boldStyle = "font-size: 14px; font-weight: bold; vertical-align: top;";
		var normalStyle = "font-size: 14px; font-weight: normal; vertical-align: top;";
		
		//Overview
		var htmlOverview = "";
		htmlOverview += "<table><tr><td style=\"vertical-align: top;\">";
		
		htmlOverview += "Test Summary";
		htmlOverview += "<table style=\"border: 1px solid #ccc; width: 460px\">";
		htmlOverview += "<tr><td style=\"" + boldStyle + "\">System Name:</td><td style=\"" + normalStyle + "\">" + inResponse.payload.systemName + "</td></tr>";
		htmlOverview += "<tr><td style=\"" + boldStyle + "\">Device Type:</td><td style=\"" + normalStyle + "\">" + inResponse.payload.deviceType + "</td></tr>";
		htmlOverview += "<tr><td style=\"" + boldStyle + "\">Platform:</td><td style=\"" + normalStyle + "\">" + inResponse.payload.platform + "</td></tr>";
		htmlOverview += "<tr><td style=\"" + boldStyle + "\">Serial Number</td><td style=\"" + normalStyle + "\">" + inResponse.payload.serialNumber + "</td></tr>";
		htmlOverview += "<tr><td style=\"" + boldStyle + "\">Total Tests:</td><td style=\"" + normalStyle + "\">" + inResponse.payload.totalTests + "</td></tr>";
		htmlOverview += "<tr><td style=\"" + boldStyle + "\">Total Conditions Detected:</td><td style=\"" + normalStyle + "\">" + inResponse.payload.totalConditionsDetected + "</td></tr>";
		htmlOverview += "<tr><td style=\"" + boldStyle + "\">Total Unique Conditions Detected:</td><td style=\"" + normalStyle + "\">" + inResponse.payload.totalUniqueConditionsDetected + "</td></tr>";
		htmlOverview += "<tr><td style=\"" + boldStyle + "\">Conditions Not Checked:</td><td style=\"" + normalStyle + "\">" + inResponse.payload.conditionsNotChecked + "</td></tr>";
		htmlOverview += "<tr><td style=\"" + boldStyle + "\">Test Pass Level:</td><td style=\"" + normalStyle + "\">" + inResponse.payload.testPassLevelWithPassed + "% passed, " + inResponse.payload.testPassLevelWithFailed + "% failed</td></tr>";
		//htmlOverview += "<tr><td style=\"" + boldStyle + "\">Overall System Health:</td><td>" + this.percentageMeterSplit("83%", 83, 0, 0, "#FFCC66", "", "") + "</td></tr>";
		htmlOverview += "</table>";
		
		htmlOverview += "</td><td style=\"vertical-align: top; padding-left: 10px;\">";
		
		htmlOverview += "Total Tests Passed and Failed";
		htmlOverview += "<table style=\"border: 1px solid #ccc; width: 460px\">";
		htmlOverview += "<tr><td>" + this.percentageMeterSplit(inResponse.payload.testPassLevelWithPassed + "% passed", inResponse.payload.testPassLevelWithPassed, 0, 0, "green", "", "") + "</td></tr>";
		htmlOverview += "<tr><td>" + this.percentageMeterSplit(inResponse.payload.testPassLevelWithFailed + "% passed", inResponse.payload.testPassLevelWithFailed, 0, 0, "red", "", "") + "</td></tr>";
		htmlOverview += "</table>";
		
		/*
		htmlOverview += "Breakdown of Issues Detected by Health-Impact";
		htmlOverview += "<table style=\"border: 1px solid #ccc; width: 460px\">";
		htmlOverview += "<tr><td>" + this.percentageMeterSplit("39 Low", 39, 0, 0, "#FFCC66", "", "") + "</td></tr>";
		htmlOverview += "<tr><td>" + this.percentageMeterSplit("16 Medium", 16, 0, 0, "#FF8C00", "", "") + "</td></tr>";
		htmlOverview += "<tr><td>" + this.percentageMeterSplit("8 High", 8, 0, 0, "red", "", "") + "</td></tr>";
		htmlOverview += "</table>";
		*/
		
		htmlOverview += "Breakdown of Issues Detected by Category";
		htmlOverview += "<table style=\"border: 1px solid #ccc; width: 460px\">";
		htmlOverview += "<tr><td>" + this.percentageMeterSplit("9 Configuration", 9, 20, 0, "#FFCC66", "red", "") + "</td></tr>";
		htmlOverview += "<tr><td>" + this.percentageMeterSplit("0 Performance", 0, 0, 0, "", "", "") + "</td></tr>";
		htmlOverview += "<tr><td>" + this.percentageMeterSplit("57 Security", 57, 25, 3, "#FFCC66", "#FF8C00", "red") + "</td></tr>";
		htmlOverview += "</table>";
		
		htmlOverview += "</td></tr></table>";
		
		this.$.overviewContent.setContent(htmlOverview);
		
		//Summary
		var htmlSummary = "";
		htmlSummary += "<table style=\"border: 1px solid #ccc; width: 940px\" cellspacing=\"0\" cellpadding=\"2\">";
		htmlSummary += "<tr style=\"background-color: #ccc; color:#000\"><td style=\"" + boldStyle + "\">Package</td><td style=\"" + boldStyle + "\">Exit Status</td><td style=\"" + boldStyle + "\">Analysis Start Time</td><td style=\"" + boldStyle + "\">Analysis End Time</td></tr>";
		for(var i = 0; i< inResponse.payload.systemModuleStats.length; i++) {
			var item = inResponse.payload.systemModuleStats[i];
			htmlSummary += this.appendPackageSummaryTR(normalStyle, item.moduleName, item.exitStatus, item.startTime, item.endTime);
		}
		htmlSummary += "</table>";
		this.$.summaryContent.setContent(htmlSummary);
	}
});